Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Jasmine is a behavior-driven development framework for testing JavaScript code. It does not rely on any other JavaScript frameworks and does not require a DOM. Jasmine is designed to be easy to configure and provides features to write different types of tests for JavaScript applications.
Writing Specs
This feature allows you to write test cases (specs) within a suite. A suite begins with a call to the global Jasmine function 'describe' with two parameters: the title of the suite and a function containing one or more specs.
describe('A suite', function() {\n it('contains spec with an expectation', function() {\n expect(true).toBe(true);\n });\n});
Setup and Teardown
This feature allows you to define code that will run before and after each spec in a suite. 'beforeEach' and 'afterEach' are used to set up preconditions and clean up after your specs.
describe('A suite', function() {\n beforeEach(function() {\n // Code to execute before each spec in this suite\n });\n afterEach(function() {\n // Code to execute after each spec in this suite\n });\n});
Asynchronous Support
This feature supports asynchronous tests, which are crucial for handling AJAX, timeouts, or any operations that rely on external systems. The 'done' callback is used to tell Jasmine when the asynchronous function has completed.
describe('Async spec', function() {\n it('supports async execution of test preparation and expectations', function(done) {\n setTimeout(function() {\n expect(true).toBe(true);\n done();\n }, 1000);\n });\n});
Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple. Mocha is often compared to Jasmine, as both provide similar test structuring capabilities, but Mocha requires assertion libraries like Chai to be fully functional, whereas Jasmine has assertions built in.
Jest is a JavaScript testing framework designed to ensure correctness of any JavaScript codebase. It allows you to write tests with an approachable, familiar and feature-rich API that gives you results quickly. Jest is used by Facebook to test all JavaScript code including React applications. It includes built-in test runners and assertion functions, similar to Jasmine, but also provides snapshot testing, a unique feature not available in Jasmine.
The jasmine
module is a command line interface and supporting code for running
Jasmine specs under Node.
The core of jasmine lives at https://github.com/jasmine/jasmine and is jasmine-core
in npm.
This module allows you to run Jasmine specs for your Node.js code. The output will be displayed in your terminal by default.
https://jasmine.github.io/edge/node.html
# Local installation:
npm install --save-dev jasmine
# Global installation
npm install -g jasmine
To initialize a project for Jasmine
jasmine init
To initialize a project for Jasmine when being installed locally
node_modules/.bin/jasmine init
or
npx jasmine init
To seed your project with some examples
jasmine examples
To run your test suite
jasmine
Customize spec/support/jasmine.json
to enumerate the source and spec files you would like the Jasmine runner to include.
You may use dir glob strings.
More information on the format of jasmine.json
can be found in the documentation
Alternatively, you may specify the path to your jasmine.json
by setting an environment variable or an option:
jasmine JASMINE_CONFIG_PATH=relative/path/to/your/jasmine.json
jasmine --config=relative/path/to/your/jasmine.json
If the name of a spec file or helper file ends in .mjs
, Jasmine will load it
as an ES module rather
than a CommonJS module. This allows the spec file or helper to import other
ES modules. No extra configuration is required.
You can also use ES modules with names ending in .js
by adding
"jsLoader": "import"
to jasmine.json
. This should work for CommonJS modules
as well as ES modules. We expect to make it the default in a future release.
Please log an issue if you have
code that doesn't load correctly with "jsLoader": "import"
.
Execute only those specs which filename match given glob:
jasmine "spec/**/critical/*Spec.js"
Or a single file:
jasmine spec/currentSpec.js
Or execute only those specs which name matches a particular regex:
jasmine --filter "adapter21*"
(where the name of a spec is the first parameter passed to describe()
)
Documentation: jasmine.github.io Jasmine Mailing list: jasmine-js@googlegroups.com Twitter: @jasminebdd
Please file issues here at Github
Copyright (c) 2008-2017 Pivotal Labs. This software is licensed under the MIT License.
FAQs
CLI for Jasmine, a simple JavaScript testing framework for browsers and Node
The npm package jasmine receives a total of 1,084,616 weekly downloads. As such, jasmine popularity was classified as popular.
We found that jasmine demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.